/* eslint valid-jsdoc: "off" */

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = (appInfo) => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = (exports = {});

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + "_1747719910684_5377";

  // add your middleware config here
  config.middleware = [];
  const path = require("path");
  // add your user config here
  const userConfig = {
    baseURL: "http://127.0.0.1:7777/qianxun/httpapi",
  };

  config.security = {
    csrf: {
      enable: false,
    },
  };

  config.cors = {
    origin: "*", // 允许所有源
    allowMethods: "GET,HEAD,PUT,POST,DELETE,PATCH",
  };

  // 模板引擎
  config.view = {
    mapping: {
      ".html": "nunjucks",
      ".nj": "nunjucks",
    },
  };
  // 添加自定义过滤器
  config.nunjucks = {
    filters: {
      round(value, decimals) {
        if (!value) return "";
        if (!decimals) decimals = 0;
        return Number(Math.round(value + "e" + decimals) + "e-" + decimals);
      },
    },
  };

  config.static = {
    prefix: "/",
    dir: path.join(appInfo.baseDir, "dist"),
  };

  // 布置版
  config.mongoose = {
    client: {
      url: 'mongodb://127.0.0.1:27017/weixinbot',
      options: {},
    },
  };

  config.view = {
    enable: false,
  };

  config.cluster = {
    listen: {
      port: 7001,
      hostname: "0.0.0.0",
    },
  };

  config.schedule = {
    enable: true,
  };

  return {
    ...config,
    ...userConfig,
  };
};
